package pa2;

import java.util.Comparator;

class AgeComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1,Student o2) {
        return o1.age - o2.age;
    }
}

public class Student implements Comparable<Student>{
    public int age;
    public String name;

    public Student(int age, String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "age=" + age +
                ", name='" + name + '\'' +
                '}';
    }

    @Override
    public int compareTo(Student o) {
        return this.age - o.age;  //大于输出正数，小于输出负数，相等输出0
    }
}
